<?php
/**
 * Created by PhpStorm.
 * FileName: ConsultController.class.php
 * User: Administrator
 * Date: 2018/5/22
 * Time: 14:55
 */

namespace WeiXin\Controller;
use Admin\Model\ConsultingModel;
use Admin\Model\ReplyModel;
/**
 * 服务咨询
 * Class ConsultController
 * @package WeiXin\Controller
 */
class ConsultController extends BaseController {
    private $consult;
    private $reply;
    function __construct() {
        $this->consult =  new ConsultingModel();
        $this->reply =  new ReplyModel();
        parent::__construct();
    }

    public function index() {
        $this->assign('pageTitle','我的咨询');
        $this->display();
    }

    public function add() {
        $this->assign('pageTitle','服务咨询');
        $this->display();
    }
    public function detail() {
        $id = I('id');
        $consult = $this->consult->where(array('id' => $id))->find();
        $reply = $this->reply->where(array('consult_id' => $id))->order('reply_time ASC')->select();
        if(!empty($reply)){
            foreach ($reply as $k=>$v){
                $reply[$k]['avatar'] = getAvatar($v['reply_id']);
                $reply[$k]['replyName'] = getUserName($v['reply_id']);
            }
        }
        $this->assign('consult',$consult);
        $this->assign('reply',json_encode($reply));
        $this->assign('pageTitle','咨询详情');
        $this->assign('consultId',$id);
        $this->display();
    }
}